<template>
  <div class="section-wrap" style="height:100%;padding-top: 40px;" v-loading="flag">
    <div class="headerBox">
    <div class="header" >
      <x-icon type="ios-arrow-left" size="" class="icon-white" @click="goBack"></x-icon>违章台账
    </div>
    </div>
    <vue-better-scroll
      class="wrapper"
      ref="scrollqq"
      :scrollbar="scrollbarObj"
      :pullDownRefresh="pullDownRefreshObj"
      :pullUpLoad="pullUpLoadObj"
      :startY='parseInt(startY)'
      @pullingUp="onPullingUp"
    >
      <!-- 头部 -->
      <div class="form-section">
        <div class="form-item form-item-style1" >
          <div class="label-title">
            <label>选择单位</label>
          </div>
          <div class="input_div">
            <input type="text"
                   v-model="params.checkDepartName"
                   :disabled="isDisabled" />
            <input type="hidden" v-model="params.departId" />
            <x-icon type="ios-arrow-right" size="22" class="icon-right" @click="getCompany(0)"></x-icon>
          </div>
        </div>
        <popup-picker title="状态" :data="optionList" v-model="value1" ></popup-picker>

        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>查询开始时间</label>
          </div>
          <group>
            <datetime v-model="startDate"  format="YYYY-MM-DD" clear-text="清除" @on-clear="clearStartDate"></datetime>
          </group>
        </div>
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>查询结束时间</label>
          </div>
          <group>
            <datetime v-model="endDate"  clear-text="清除" @on-clear="clearEndDate"></datetime>
          </group>
        </div>
        <p class="search-btn" @click="search">查询</p>
        <div class="info_div2">
          <div class="form-item">
            <div><span>违章数量：{{totalCount}}个</span></div>
          </div>
        </div>
        <div class="project_div">
          <ul class="project_list">
            <li v-for='(item,index) in accpentlist' :key="index" @click="GetAssessmentInfo(item.id)">
              <div class="lf">
                <img :src="item.weizurl" alt="" >
                <p >{{item.weizPhenItemListName}}</p>
                <span>{{item.status}}</span>
              </div>
              <div class="rf">
                <p class="project_time">{{item.weizDate.substring(0,10)}}</p>
              </div>
              <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
            </li>
          </ul>
        </div>
      </div>
    </vue-better-scroll>
    <!--classValue 显示隐藏   data树结构  nodeClicK节点点击返回值  name显示的字段  -->
    <div v-transfer-dom>
      <popup v-model="classValue" width="100%">
                <ztree
          :data="data"
          @nodeClick="nodeClick"
          :name="'departName'"

        ></ztree>
      </popup>
    </div>

    <!-- <img src="/static/images/add_pro_icon.png" class="add_btn" @click="GetAssessmentInfo({rocordStatus:0})"> -->
  </div>

</template>
<script>
  import ztree from "@commonComponents/tree"
  import selectDepart from "@commonComponents/selectDepart/selectDepart";
  import formatDate from "../../utils/formatDate";
  import VueBetterScroll from "vue2-better-scroll"
  import {
    XHeader,
    Tabbar,
    TabbarItem,
    Group,
    Cell,
    TransferDom,
    PopupPicker,
    Popup,
  } from "vux";
  export default {
    directives: {
      TransferDom
    },
    data() {
      return {
        flag:false,
        optionList:[['全部','待整改','待验收','已关闭']],
        value1:['全部'],
        ruleForm:{
          status:['全部']
        },
        /*下拉刷新*/
        resultlist:[''],
        scrollbarObj:{fade:true},
        pullDownRefreshObj:false,
        pullUpLoadObj:{
          threshold:0,
          txt:{
            more:"加载更多",
            noMore:"没有更多数据了"
          }
        },
        startY:0,
        scrollToX:0,
        scrollToY:0,
        scrollToTime:700,
        isDisabled: true,
        totalCount: 0,
        accpentlist: [],
        classValue: false,
        data: [],
        params: {
          isall: "1",
          departId: null,
          weizDateStart: "",
          weizDateEnd: "",
          status:['全部'],
          skipCount: 0,
          maxResultCount: 10
        },
        startDate: new Date().getFullYear()+"-01-01",
        endDate:formatDate(new Date(),'yyyy-MM-dd'),
        selectDepartType: 0,
        detailInfo:{}
      };
    },
    components: {
      ztree,
      selectDepart,
      Popup,
      VueBetterScroll,
      PopupPicker
    },
    mounted(){
        let that = this;
        this.$bridge.registerHandler("setToken", function(data) {
                         that.$store.state.Authorization =
          "Bearer " + data;
          that.getData();
            //这里data ioS返回的是token值(字符串)
        });

        this.connectWebViewJavascriptBridge(function(bridge) {
            bridge.registerHandler("setToken", function(data) {
                             that.$store.state.Authorization =
          "Bearer " + data;
          that.getData();
                  //这里data android返回的是token值(字符串)

            });
        });
    },
    created() {
      this.getData();
    },
    methods: {
      connectWebViewJavascriptBridge(callback) {
            if (window.WebViewJavascriptBridge) {
                callback(WebViewJavascriptBridge);
            } else {
                document.addEventListener(
                "WebViewJavascriptBridgeReady",
                function() {
                    callback(WebViewJavascriptBridge);
                },
                false
                );
            }
        },
      filterStatus(n){
        var str=''
        switch(n){
          case '待整改':str = 1;break;
          case '待验收':str = 2;break;
          case '已关闭':str = 3;break;
            default :str = null;break;
        }
        return str
      },
      search(){
        this.accpentlist=[]
        this.getData()
      },
      getData() {
        var param1 = {}
        for(var i in this.params){
          param1[i] = this.params[i]
        }
        if (this.startDate) {
          param1.weizDateStart = this.startDate + " 00:00:00";
        }
        if (this.endDate) {
          param1.weizDateEnd = this.endDate + " 00:00:00";
        }
        param1.status = this.filterStatus(this.value1[0])
        this.flag=true
          this.$axiosAjax.getAllWZmobile(param1).then(res => {
            this.flag=false
            res.data.result.items.map((item,index)=>{
              switch(item.status){
                case 1:item.status = '待整改';break;
                case 2:item.status = '待验收';break;
                case 3:item.status = '已关闭';break;
                default :item.status = '全部';break;
              }
            })

            this.totalCount = res.data.result.totalCount;
            let relist = res.data.result.items;
            this.accpentlist = this.accpentlist.concat(relist);
            let totalAllCount = res.data.result.totalCount;
            let resultCount = this.accpentlist.length;
            if (parseInt(resultCount) < parseInt(totalAllCount)) {
              this.$refs["scrollqq"].forceUpdate(true);
            } else {
              this.$refs["scrollqq"].forceUpdate(false);
            }

        });
      },
      GetAssessmentInfo(id) {
        this.$router.push({path:'breakQueryDetail',query:{
            id:id
          }})
      },
      goBack() {
      this.$bridge.callHandler({
              type: 'closePage',
              data: {}
            });
      },
      getCompany(type) {
        this.examinedUnits();
        //this.classValue = true;
        this.selectDepartType = type;
      },
      examinedUnits() {
        //debugger;//单位
        this.$axiosAjax.examinedUnits({parentId: this.$store.state.departId||-1}).then((res) => {
          if (res.data.success == true) {
             this.classValue = true;
             this.data = res.data.result;
            console.log(this.data);
          }
        }).catch(
          (err) => {

          }
        )

      },
      nodeClick(item) {
      //   if (
      //     item.departType == 6 ||
      //     item.departType == 7 ||
      //     item.departType == 8
      //   ) {

      //  this.params.departId = item.id;
      //   this.params.checkDepartName = item.departName;
      //     this.classValue = false;
      //   } else {
      //     this.$vux.toast.text("只能选择项目部");
      //   }
      this.params.departId = item.id;
      this.params.checkDepartName = item.departName;
      this.classValue = false;
      },
      getTableTypeList() {
        this.$axiosAjax
          .getTableTypeList(this.params)
          .then(res => {
            if (res.data.result.isSuccess == true) {
              this.tableType = res.data.result.data;
            }
          })
          .catch(err => { });
      },
      selectedDepart(data) {
        this.params.departId = data.id;
        if (this.selectDepartType == 0) {
          this.params.checkDepartName = data.departName;
        } else {
          this.params.beCheckDepartName = data.departName;
        }
        this.classValue = false;
      },
      clearStartDate() {
        this.startDate = "";
      },
      clearEndDate() {
        this.endDate = "";
      },
      onPullingUp() {
        let limitcount = this.accpentlist.length;
        this.params.skipCount = limitcount;
        this.getData();
      },
      onPullingDown() {
        this.getData();
      },
    }
  };
</script>
<style>

  .weui-cell__ft::after{
  height: 8px!important;
  width: 8px!important;
  color: #9c9c9c!important;
  border-color: #9c9c9c!important;
  }
  .vux-cell-box .weui-label{
    color: #333;
    font-weight:500;
    font-size:14px;
  }
  .vux-cell-box .weui-cell{
    padding:20px 26px 20px  0!important;
    margin-left:20px;
    border-bottom: 1px solid #efeff4;
  }
</style>
<style lang="less" scoped>
  .search-btn{
    width: 200px;
    line-height: 40px;
    border-radius: 20px;
    margin: 23px auto;
    color: #fff;
    background: #469b7a;
    text-align: center;
  }
  .statues{
    font-size: 12px;
    font-weight: bold;

  }
  .classifyOneName{
    font-size: 12px;
    color: #666;
  }
  .lf{
    float: left;
    height: 100%;
    width: 70%;
    line-height: 25px;
    display:flex;
    align-items: center;
    img{
      width:40px;
      height:40px;
      float:left;
      margin-right:10px;
    }
    p{
      width:130px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp:2;
      -webkit-box-orient:vertical;
      float:left;
    }
    span{
      float:left;
    }
  }
  .rf{
    float:right;
    height: 100%;
    width: 30%;
    display: flex;
    align-items: center;
    p{
      height:50px;
      line-height: 50px;

    }
  }
  .form-item {
    .input_div

    {
      .vux-x-icon

      {
        fill: #999;
        float: right;
        margin-top: 18px;
      }

    }
  }

  .project_div {
    .project_list

    {
      box-sizing: border-box;
      padding-left: 10px;
      li

      {
        border-bottom: 1px solid #efeff4;
        height: 77px;
        position: relative;
        padding-top: 10px;
        padding-right: 22px;
        h4

        {
          width: calc(100% - 50px);
          text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;
          font-size: 16px;
          margin-bottom: 8px;
          font-weight: bold;
        }

        p {
          span

          {
            font-size: 14px;
            color: #666;
          }

          span:first-child {
            margin-right: 40px;
          }

        }

        .project_status {
          margin-top: 14px;
          strong

          {
            font-size: 12px;
          }

          strong.project_status1 {
            color: #ff7333;
          }

          strong.project_status2 {
            color: #469b7a;
          }

        }

        .vux-x-icon {
          fill: #999;
          float:right;
          margin-top:-42px;
        }

      }
    }
  }

  .add_btn {
    position: fixed;
    height: 62px;
    width: 62px;
    right: 30px;
    bottom: 35px;
  }
</style>
